<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Validator;

class System extends Model
{
    protected $fillable = ['webname', 'copyright'];
    protected $dateFormat = 'U';

    //更新网站
    public function edit($data)
    {
        $rule = [
            'webname' => 'bail|required',
            'copyright' => 'required'
        ];

        $msg = [
            'webname.required' => '网站标题不能为空',
            'copyright.required' => '版权信息不能为空'
        ];
        $validator = Validator::make($data, $rule, $msg);
        if ($validator->fails()) {
            return $validator->errors()->first();
        }
        $webInfo = $this->find($data['id']);
        $webInfo->webname = $data['webname'];
        $webInfo->copyright = $data['copyright'];
        $result = $webInfo->save();
        if ($result) {
            return 1;
        }else {
            return '网站更新失败';
        }
    }
}
